import 'package:flutter/material.dart';
import 'package:flutterlib/common/constants/constants.dart';
import 'package:flutterlib/common/style/meterial_design_icons.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/common/utils/utils.dart';
import 'package:flutterlib/pages/interest/viewmodel/interest_store.dart';
import 'package:flutterlib/pages/post/report/report_create.dart';
import 'package:flutterlib/pages/post/report/report_list_normal_widget_page.dart';
import 'package:flutterlib/widgets/quhui_tabbar_widget.dart';
import 'package:flutterlib/widgets/round_underline_tabindicator.dart';

//用于加载内部继承上下拉的页面state的外部容器页面，
//适用于带tabbar，内部是list的页面的改造

class ParentDelegate{
  Function callSend;
}
typedef CallSend = Function();
class Page extends StatefulWidget {
  Page({Key key}) : super(key: key);

  @override
  PageState createState() => PageState();
}

class PageState extends State<Page>
    with SingleTickerProviderStateMixin {
  final SettingsStore store =
      Provider.of<SettingsStore>(currentContext, listen: false);
  InterestStore interestStore = InterestStore();
  int _tabIndex = 0;
  List<Widget> tabPageView = new List();
  List<Widget> tabViews = new List();
  ParentDelegate parentDelegate = ParentDelegate();

  @override
  void initState() {
    super.initState();

    tabPageView.add(new ReportCreate(
      delegate: parentDelegate,
    ));
    tabViews.add(renderItem("提交反馈", 0));
    tabPageView.add(new ReportNormalListWidgetPage(
      name: "历史反馈",
      interestId: 0,
      type: 0,
    ));
    tabViews.add(renderItem("历史反馈", 0));

  }

  renderItem(String item, int i) {
    return VgTab(
      child: new Text(
        item,
        style: QuhuiConstant.smallSubText,
        maxLines: 1,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    print(context.widget.toStringShort());

      ///绘制顶部 tab 控件
      return new QuhuiTabBarWidget(
        key: ValueKey(context.widget.toStringShort()),
        type: TabType.top,
        tabBarType: 1,
        tabItems: tabViews,
        resizeToAvoidBottomPadding: false,
        tabViews: tabPageView,
        backgroundColor: QuhuiColors.white,
        indicatorColor: QuhuiColors.mainThemeColor,
        title: Text("意见反馈", style: QuhuiConstant.middleTextBold,),
        leading: MyBackButton(),
        actions: [
          publishButton,
        ],

        // actions: InkWell(
        //   onTap: (){
        //     parentDelegate.callSend();
        //   },
        //   child: Text("发布", style: QuhuiConstant.middleText,),
        // ),
        onPageChanged: (index) {
          _tabIndex = index;
        },
      );
  }

  Widget get publishButton => Padding(
    padding: EdgeInsets.fromLTRB(0, 10, 10, 10),
    child: MaterialButton(
      color: currentThemeColor,
      minWidth: 90.w,
      height: 30.h,
      padding: EdgeInsets.all(5),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(13.w),
      ),
      materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Padding(
            padding: EdgeInsets.only(right: 6.w),
            child: Icon(MIcon.send, size: 14,),
          ),
          Text(
            '发布',
            style: TextStyle(
              color: Colors.white,
              fontSize: 15.sp,
              height: 1.24,
            ),
          ),
        ],
      ),
      onPressed: (){
        parentDelegate.callSend();
      },
    ),
  );

  int getInterestId() {
    if (_tabIndex == 0) {
      return 0;
    }
    var interests = store.interests;
    return interests[_tabIndex - 1]?.id;
  }
}
